package com.fcat.common.user.enums;

/**
 * @description 下发状态枚举类
 * @author：zhouqilin
 * @date：2017/7/26 11:21
 */
public enum StateCode {

    //gateway的状态
//    SUCCESS_SERVICE(0, "成功"),
//    SYSTEM_EXCEPTION(-1, "系统异常"),
    NO_TOKEN(401, "请求头的 token 不能为空"),
    INVALID_TOKEN(-401, "授权token无效或过期(keycloak)"),
    INVALID_TOKEN2(-402, "登录账户连接过期，需重新登录"),
    INVALID_TOKEN3(-403, "该账户在其他客户端电脑登录，请确认账户信息是否安全"),


    SUCCESS_SERVICE(0, "成功"),
    SYSTEM_EXCEPTION(-1, "系统异常"),
    PARAMS_EXCEPTION(-2, "参数异常"),

    UNKNOWN_EXCEPTION(-101, "未知异常"),
    CUSTOM_EXCEPTION(-102, "{0}"),
    SEARCH_EXCEPTION(-110, "查询异常"),
    SAVE_EXCEPTION(-111, "保存异常"),
    UPDATE_EXCEPTION(-112, "更新异常"),
    REMOVE_EXCEPTION(-113, "删除异常"),
    ERROR_SESSION_INVALID(-120, "会话失效"),
    ERROR_CHECK_PASSWORD_FAILED(-121, "账号名或密码错误"),
    ERROR_BIND_CITY_CODE(-122, "账号未绑定地市编码"),
    ERROR_FIRST_USE(-123, "账号首次使用"),
    ERROR_PARAMS_WRONGFUL(-124, "参数校验错误"),
    ERROR_PARAMS_WRONGFUL_MSG(-128, "参数校验错误,{0}"),
    ERROR_REQUEST_INVALID(-125, "非法访问"),
    ERROR_NOT_FOUND(-126, "访问无效，数据不存在"),
    ERROR_FORBIDDEN(-127, "拒绝访问，用户未授权"),
    ERROR_CERT_NOT_FOUND(-128, "证书不存在"),
    ERROR_CERT_VALIDATE(-129, "证书解析错误"),
    ERROR_FEIGN(-116, "FEIGN调用失败"),
    ERROR_VERIFY(-131, "用户验证错误！"),

    ERROR_OLD_PASSWORD_FAILED(-140, "旧密码错误"),

    ERROR_DATA_EXISTS(-310, "数据重复"),
    ERROR_ATTRIBUTES_INCLUDE(-311, "attributes参数key错误");



////    UNAUTHORIZED(-401, "用户未授权或用户名密码错误"),
//
//    UNAUTHORIZED_CLIENT(-402, "客户端{0}未授权");

    int code;

    String msg;

    StateCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static StateCode get(int code) {
        for (StateCode stateCode : values()) {
            if (stateCode.getCode() == code) {
                return stateCode;
            }
        }
        return UNKNOWN_EXCEPTION;
    }

    public static StateCode get(String msg) {
        for (StateCode stateCode : values()) {
            if (stateCode.getMsg().equalsIgnoreCase(msg)) {
                return stateCode;
            }
        }
        return UNKNOWN_EXCEPTION;
    }
}
